//
//  CarMangerViewController.m
//  AnnCar_user
//
//  Created by LiBenCan on 17/10/26.
//  Copyright © 2017年 LiBenCan. All rights reserved.
//

#import "CarMangerViewController.h"
#import "CarCell.h"
#import "AddAddressViewController.h"
#import "CarAddViewController.h"
@interface CarMangerViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableV;
@property (nonatomic,strong)NSMutableArray *dataArr;//数据
@property (nonatomic,strong)UIButton *addBtn;//添加按钮
@end

@implementation CarMangerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTitleWithTitle:@"我的车辆"];
    [self initLeftBarButtonWithImage:@"back"];
    [self.view addSubview:self.tableV];
    [self.view addSubview:self.addBtn];
}
-(NSMutableArray *)dataArr//初始化数组
{
    if (!_dataArr) {
        _dataArr = @[@"",
                     @"",
                     @""].mutableCopy;
    }
    return _dataArr;
}
//创建TableView
-(UITableView *)tableV
{
    if (!_tableV) {
        _tableV = [[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREENW, SCREENH-64-50*screenW_6) style:UITableViewStyleGrouped];
        _tableV.backgroundColor = backColor;
        _tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableV.showsVerticalScrollIndicator = NO;
        _tableV.rowHeight = 150*screenW_6;
        _tableV.delegate = self;
        _tableV.dataSource = self;
    }
    return _tableV;
}

#pragma Mark TableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
//行
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArr.count;
}
//区头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 5*screenW_6;
}
//区尾高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.000001;
}
//加载Cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CarCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CarCell"];
    if (cell == nil) {
        cell = [[CarCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CarCell"];
    }
    [cell setDataDic:nil Section:indexPath.section];
    //chooseNumber 0：默认 1:编辑 2:删除
    cell.chooseBlock = ^(NSInteger chooseNumber){
        
    };
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_selectCarBlock) {
        _selectCarBlock(@"回调车的信息");
        [self.navigationController popViewControllerAnimated:YES];
    }
}
//充值按钮
-(UIButton *)addBtn
{
    if (!_addBtn) {
        
        _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _addBtn.frame = CGRectMake(0, SCREENH-64-50*screenW_6, SCREENW,50*screenW_6);
        [_addBtn setTitle:@"添加车辆" forState:UIControlStateNormal];
        [_addBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _addBtn.backgroundColor = blueColor;
        [_addBtn setImage:[UIImage imageNamed:@"My_addPerson"] forState:UIControlStateNormal];
        [_addBtn setImageEdgeInsets:UIEdgeInsetsMake(15*screenW_6,SCREENW/2-50*screenW_6,15*screenW_6,SCREENW/2-30*screenW_6)];
        [_addBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,SCREENW/2-40*screenW_6,0,SCREENW/2-60*screenW_6)];
        [_addBtn addTarget:self action:@selector(rechargeSelect) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _addBtn;
}
//跳转添地址
-(void)rechargeSelect
{
    CarAddViewController *VC = [CarAddViewController new];
    [self.navigationController pushViewController:VC animated:YES];
}

@end
